<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>aes测试</title>
	<script type="text/javascript" src="aes.js"></script>
	<script type="text/javascript" src="../components/mode-ecb.js"></script>
	<script type="text/javascript" src="../components/tripledes-min.js"></script>
</head>
<body>
	
</body>

<script type="text/javascript">

	//加密
	function Encrypt(word){
		 var key = CryptoJS.enc.Utf8.parse("abcdefgabcdefg12");

		 var srcs = CryptoJS.enc.Utf8.parse(word);
		 var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
         return encrypted.toString();
	}

	//解密
	function Decrypt(word){
		 var key = CryptoJS.enc.Utf8.parse("abcdefgabcdefg12");

		 var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
		 return CryptoJS.enc.Utf8.stringify(decrypt).toString();
	}
//	alert(Encrypt("我爱你"));
//	alert(Decrypt(Encrypt("我爱你")))

	//des加密
	var message = '411122199307287547';
	var key = '12345678';

	function encryptByDES(message, key) {
		var keyHex = CryptoJS.enc.Utf8.parse(key);
		var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
			mode: CryptoJS.mode.ECB,
			padding: CryptoJS.pad.Pkcs7
		});
		return encrypted.toString();
	}

	function decryptByDES(ciphertext, key) {
		var keyHex = CryptoJS.enc.Utf8.parse(key);

		// direct decrypt ciphertext
		var decrypted = CryptoJS.DES.decrypt({
			ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
		}, keyHex, {
			mode: CryptoJS.mode.ECB,
			padding: CryptoJS.pad.Pkcs7
		});

		return decrypted.toString(CryptoJS.enc.Utf8);
	}

	var ciphertext = encryptByDES(message, key);

	alert(ciphertext);
	var plaintext = decryptByDES(ciphertext, key);
	alert(plaintext);
</script>
</html>